package ui;

import com.sun.lwuit.Calendar;
import com.sun.lwuit.Command;
import com.sun.lwuit.Dialog;
import com.sun.lwuit.layouts.BorderLayout;
import java.util.Date;

/**
 *
 * @author Shayan
 */
public class CalendarDialog extends Dialog {

    Command cmdBack;
    Command cmdChoose;
    private boolean choosed = false;

    public boolean getChoosed() {
        return choosed;
    }

    public static Date show(Date day) {
        CalendarDialog form = new CalendarDialog();
        form.setDay(day);
        form.show(5, 5, 5, 5, true, true);
        if (form.getChoosed()) {
            return form.getSelectedDay();
        }
        return day;
    }

    public Date getSelectedDay() {
        return new Date(calendar.getSelectedDay());
    }

    public void setDay(Date day) {
        calendar.setDate(day);
    }
    private Calendar calendar;

    public CalendarDialog() {
        super("Select date");
        setLayout(new BorderLayout());
        calendar = new Calendar();
        
        cmdBack = new Command("Back");
        setBackCommand(cmdBack);
        addCommand(cmdBack);

        cmdChoose = new Command("Choose");
        addCommand(cmdChoose);
    }

    protected void onShow() {
        super.onShow();
        addComponent(BorderLayout.CENTER, calendar);
    }


    protected void actionCommand(Command cmd) {

        if (cmd == cmdBack) {
            choosed = false;
            dispose();
            return;
        }

        if (cmd == cmdChoose) {
            choosed = true;
            dispose();
            return;
        }
    }
}
